let href = location.href;
function getUrldata(url) {
    url = decodeURI(url)
    // console.log(queryString)
    let reg = /^[^\s]+\?([^&\s\d]+=[^\s]+)*/
    let match = reg.exec(url)[1];
    if (!match) {//表示没匹配到
        console.warn("没有匹配到相应的query参数")
        return null
    }
    var queryArr = match.split("&");
    // console.log(queryArr);
    var queryobj = {};
    queryArr.forEach(item => {
        var itemarr = item.split("=")
        queryobj[itemarr[0]] = itemarr[1];
    })
    return queryobj;
}
let qr = getUrldata(href);
var htmlnav = `
        <a href="./index.html">首页</a>&nbsp;>&nbsp;<a href="./category.html">全部分类</a>&nbsp;>&nbsp;<a href="#">${qr.title}</a>
        <button>筛选</button>`;
$("nav").html(htmlnav);



addProductContent();
talkContent();



function addProductContent() {
    let productid=qr.productid;
    $.ajax({
        url:"http://chst.vip:1234/api/getproduct",
        type:"Get",
        data:{
            productid
        },
        success(sus){
            var item=sus.result[0];
            var html="";
            html=`
            <div class="productImg">${item.productImg}</div>
            <h4>${item.productName}</h4>
            ${item.bjShop}`
            $("main").html(html);
        }
    })
}
function talkContent(){
    let productid = qr.productid;
    $.ajax({
        url:"http://chst.vip:1234/api/getproductcom",
        type:"Get",
        data:{
            productid
        },
        success(sus){
            var html=`<h3>网友评价</h3>`;
            sus.result.forEach(item=>{
                html+=`
                <div class="comItem">
                    <p class=comName>${item.comName}<span>${item.comTime}</span></p>
                    <p class="comContent">${item.comContent}</p>
                    <p class="comFrom"><span>${item.comFrom}</span></p>
                </div>`
            })
            $(".talk").html(html);
        }
    })
}